//
//  LoadingView.swift
//  ezyform
//
//  Created by Moennig Q on 2021/11/18.
//  Copyright © 2021 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import SnapKit
class LoadingView: UIView {
    
    let loadingLabel = BaseLabel()
    let actitveView = UIActivityIndicatorView()
    let imageView = UIImageView()
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initUI()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI() {
        self.backgroundColor = UIColor(white: 0, alpha: 0.5)
        //添加中间矩形黑色区域, 80*80
        //back view
        let backView = UIView()
        backView.backgroundColor = UIColor(hexStr: Constant.ThemeColorHexStr)
        self.addSubview(backView)
        backView.layer.cornerRadius = Constant.BackViewCornerRadius
        backView.snp.makeConstraints { (make) in
            make.width.height.greaterThanOrEqualTo(0)
            make.width.greaterThanOrEqualTo(backView.snp.height).multipliedBy(1.2)
            make.center.equalToSuperview()
        }
        //
        actitveView.style = .whiteLarge
        backView.addSubview(actitveView)
        actitveView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(15)
            make.height.width.greaterThanOrEqualTo(0)
            make.centerX.equalToSuperview()
        }
        imageView.image = R.image.loading_updated_icon()
        imageView.contentMode = .scaleAspectFit
        backView.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.width.height.equalTo(30)
            make.center.equalTo(actitveView)
        }
        //loading
        loadingLabel.textColor = .white
        loadingLabel.setFont(R.font.interRegular(size: 16))
        loadingLabel.textAlignment = .center
        backView.addSubview(loadingLabel)
        loadingLabel.snp.makeConstraints { (make) in
            make.top.equalTo(actitveView.snp.bottom).offset(10)
            make.left.equalTo(5)
            make.right.equalTo(-5)
            make.height.greaterThanOrEqualTo(0)
            make.bottom.equalToSuperview().offset(-15)
        }
        actitveView.startAnimating()
        imageView.isHidden = true
    }
}
